async function initSystem () {
    const origin = self.context.origin + '/'
    const import_map_json = origin + "workerspace_map.json"
    const resposne = await fetch(import_map_json);
    const json = await resposne.json();
    importScripts(json.systemJs);

    System.instantiate = function (url) {
        var n = this.registerRegistry[url];
        if (n) {
            this.registerRegistry[url] = null;
            return n;
        }
        let fileUrl = url;
        if (url in json.imports) {
            fileUrl = origin + json.imports[url];
        } else if (url.startsWith('cc')) {
            fileUrl = origin + 'fake_cc.js';
        }
        importScripts(fileUrl);
        var r = this.getRegister();
        var n = this.registerRegistry[url];
        if (!n && r && typeof r[1] === "function") {
            var o = r[1](function(){});
            var m = o && o.execute && o.execute();
            n = this.registerRegistry[url] || m;
        }
        if (!n) {
            console.error("Unable to load " + url);
        }
        this.registerRegistry[url] = null;
        return n;
    }

    System.resolve = function (id, parentUrl) {
        if (id.startsWith('./') && id in json.chunks) {
            return json.chunks[id];
        }
        return id;
    }
}